﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace Sidvall.UI.Wpf.Converters
{
    public class ObjectToVisibilityConverter : IValueConverter
    {
        #region Public Members

        #region Collapsed

        private bool _Collapsed = true;
        public bool Collapsed
        {
            get
            {
                return _Collapsed;
            }
            set
            {
                _Collapsed = value;
            }
        }

        #endregion
        #region Not

        private bool _Not = false;
        public bool Not
        {
            get
            {
                return _Not;
            }
            set
            {
                _Not = value;
            }
        }

        #endregion

        #region Convert

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (this.Not)
            {
                if (value == null)
                    return Visibility.Visible;
                if (this.Collapsed)
                    return Visibility.Collapsed;
                return Visibility.Hidden;
            }
            else
            {
                if (value != null)
                    return Visibility.Visible;
                if (this.Collapsed)
                    return Visibility.Collapsed;
                return Visibility.Hidden;
            }
        }

        #endregion
        #region ConvertBack

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        #endregion

        #endregion
    }
}
